export const API = "API";

/**
 *
 * @param newApi 修改api地址，否则获得当前api
 * @returns 当前api地址
 */
export function initAPI(newApi?: string) {
	if (newApi) {
		window.localStorage.setItem(API, newApi);
		return newApi;
	}

	const defaultApi = "localhost:4000";
	const api = window.localStorage.getItem(API);

	if (api === null) {
		window.localStorage.setItem(API, defaultApi);
		return defaultApi;
	}

	return api;
}
